<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.13"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>lwIP: src/core/mem.c File Reference</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtreedata.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
  $(document).ready(initResizable);
</script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectalign" style="padding-left: 0.5em;">
   <div id="projectname">lwIP
   &#160;<span id="projectnumber">2.1.2</span>
   </div>
   <div id="projectbrief">Lightweight IP stack</div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.13 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
$(function() {
  initMenu('',true,false,'search.php','Search');
  $(document).ready(function() { init_search(); });
});
</script>
<div id="main-nav"></div>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
      <div id="nav-sync" class="sync"></div>
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
$(document).ready(function(){initNavTree('mem_8c.html','');});
</script>
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div class="header">
  <div class="summary">
<a href="#nested-classes">Data Structures</a> &#124;
<a href="#define-members">Macros</a> &#124;
<a href="#func-members">Functions</a> &#124;
<a href="#var-members">Variables</a>  </div>
  <div class="headertitle">
<div class="title">mem.c File Reference</div>  </div>
</div><!--header-->
<div class="contents">
<div class="textblock"><code>#include &quot;<a class="el" href="opt_8h.html">lwip/opt.h</a>&quot;</code><br />
<code>#include &quot;<a class="el" href="mem_8h.html">lwip/mem.h</a>&quot;</code><br />
<code>#include &quot;<a class="el" href="def_8h.html">lwip/def.h</a>&quot;</code><br />
<code>#include &quot;<a class="el" href="sys_8h.html">lwip/sys.h</a>&quot;</code><br />
<code>#include &quot;<a class="el" href="stats_8h.html">lwip/stats.h</a>&quot;</code><br />
<code>#include &quot;<a class="el" href="err_8h.html">lwip/err.h</a>&quot;</code><br />
<code>#include &lt;string.h&gt;</code><br />
</div><table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="nested-classes"></a>
Data Structures</h2></td></tr>
<tr class="memitem:"><td class="memItemLeft" align="right" valign="top">struct &#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="structmem.html">mem</a></td></tr>
<tr class="separator:"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table><table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="define-members"></a>
Macros</h2></td></tr>
<tr class="memitem:a278694c2333c9826f21ddd2c2d220f66"><td class="memItemLeft" align="right" valign="top">#define&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="mem_8c.html#a278694c2333c9826f21ddd2c2d220f66">MIN_SIZE</a>&#160;&#160;&#160;12</td></tr>
<tr class="separator:a278694c2333c9826f21ddd2c2d220f66"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table><table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="func-members"></a>
Functions</h2></td></tr>
<tr class="memitem:a44a136e3b70c36abb6f8dc060c778113"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="mem_8c.html#a44a136e3b70c36abb6f8dc060c778113">mem_init</a> (void)</td></tr>
<tr class="separator:a44a136e3b70c36abb6f8dc060c778113"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a65169147c44e9db60d997819af9b455c"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="mem_8c.html#a65169147c44e9db60d997819af9b455c">mem_free</a> (void *rmem)</td></tr>
<tr class="separator:a65169147c44e9db60d997819af9b455c"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a7e6b7f11bb50bead9b35515d9a517124"><td class="memItemLeft" align="right" valign="top">void *&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="mem_8c.html#a7e6b7f11bb50bead9b35515d9a517124">mem_trim</a> (void *rmem, mem_size_t new_size)</td></tr>
<tr class="separator:a7e6b7f11bb50bead9b35515d9a517124"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:af418ade27d91d41e6143dba2cc246b0f"><td class="memItemLeft" align="right" valign="top">void *&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="mem_8c.html#af418ade27d91d41e6143dba2cc246b0f">mem_malloc</a> (mem_size_t size_in)</td></tr>
<tr class="separator:af418ade27d91d41e6143dba2cc246b0f"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ab0bdc525971701883f2065e7fb257a24"><td class="memItemLeft" align="right" valign="top">void *&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="mem_8c.html#ab0bdc525971701883f2065e7fb257a24">mem_calloc</a> (mem_size_t count, mem_size_t size)</td></tr>
<tr class="separator:ab0bdc525971701883f2065e7fb257a24"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table><table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="var-members"></a>
Variables</h2></td></tr>
<tr class="memitem:a6da602f2bbf1d555556f9260b3b8ad5f"><td class="memItemLeft" align="right" valign="top">u8_t&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="mem_8c.html#a6da602f2bbf1d555556f9260b3b8ad5f">ram_heap</a> [((((((1600)+1 - 1U) &amp;~(1 -1U))+(2U *(((sizeof(struct mem))+1 - 1U) &amp;~(1 -1U))))+1 - 1U))]</td></tr>
<tr class="separator:a6da602f2bbf1d555556f9260b3b8ad5f"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table>
<a name="details" id="details"></a><h2 class="groupheader">Detailed Description</h2>
<div class="textblock"><p>Dynamic memory manager</p>
<p>This is a lightweight replacement for the standard C library malloc().</p>
<p>If you want to use the standard C library malloc() instead, define MEM_LIBC_MALLOC to 1 in your lwipopts.h</p>
<p>To let <a class="el" href="mem_8c.html#af418ade27d91d41e6143dba2cc246b0f">mem_malloc()</a> use pools (prevents fragmentation and is much faster than a heap but might waste some memory), define MEM_USE_POOLS to 1, define MEMP_USE_CUSTOM_POOLS to 1 and create a file "lwippools.h" that includes a list of pools like this (more pools can be added between _START and _END):</p>
<p>Define three pools with sizes 256, 512, and 1512 bytes LWIP_MALLOC_MEMPOOL_START LWIP_MALLOC_MEMPOOL(20, 256) LWIP_MALLOC_MEMPOOL(10, 512) LWIP_MALLOC_MEMPOOL(5, 1512) LWIP_MALLOC_MEMPOOL_END </p>
</div><h2 class="groupheader">Macro Definition Documentation</h2>
<a id="a278694c2333c9826f21ddd2c2d220f66"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a278694c2333c9826f21ddd2c2d220f66">&#9670;&nbsp;</a></span>MIN_SIZE</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">#define MIN_SIZE&#160;&#160;&#160;12</td>
        </tr>
      </table>
</div><div class="memdoc">
<p>All allocated blocks will be MIN_SIZE bytes big, at least! MIN_SIZE can be overridden to suit your needs. Smaller values save space, larger values could prevent too small blocks to fragment the RAM too much. </p>

</div>
</div>
<h2 class="groupheader">Function Documentation</h2>
<a id="ab0bdc525971701883f2065e7fb257a24"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ab0bdc525971701883f2065e7fb257a24">&#9670;&nbsp;</a></span>mem_calloc()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void* mem_calloc </td>
          <td>(</td>
          <td class="paramtype">mem_size_t&#160;</td>
          <td class="paramname"><em>count</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">mem_size_t&#160;</td>
          <td class="paramname"><em>size</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div><div class="memdoc">
<p>Contiguously allocates enough space for count objects that are size bytes of memory each and returns a pointer to the allocated memory.</p>
<p>The allocated memory is filled with bytes of value zero.</p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">count</td><td>number of objects to allocate </td></tr>
    <tr><td class="paramname">size</td><td>size of the objects to allocate </td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>pointer to allocated memory / NULL pointer if there is an error </dd></dl>

</div>
</div>
<a id="a65169147c44e9db60d997819af9b455c"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a65169147c44e9db60d997819af9b455c">&#9670;&nbsp;</a></span>mem_free()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void mem_free </td>
          <td>(</td>
          <td class="paramtype">void *&#160;</td>
          <td class="paramname"><em>rmem</em></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div><div class="memdoc">
<p>Put a struct mem back on the heap</p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">rmem</td><td>is the data portion of a struct mem as returned by a previous call to <a class="el" href="mem_8c.html#af418ade27d91d41e6143dba2cc246b0f">mem_malloc()</a> </td></tr>
  </table>
  </dd>
</dl>

</div>
</div>
<a id="a44a136e3b70c36abb6f8dc060c778113"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a44a136e3b70c36abb6f8dc060c778113">&#9670;&nbsp;</a></span>mem_init()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void mem_init </td>
          <td>(</td>
          <td class="paramtype">void&#160;</td>
          <td class="paramname"></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div><div class="memdoc">
<p>Zero the heap and initialize start, end and lowest-free </p>

</div>
</div>
<a id="af418ade27d91d41e6143dba2cc246b0f"></a>
<h2 class="memtitle"><span class="permalink"><a href="#af418ade27d91d41e6143dba2cc246b0f">&#9670;&nbsp;</a></span>mem_malloc()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void* mem_malloc </td>
          <td>(</td>
          <td class="paramtype">mem_size_t&#160;</td>
          <td class="paramname"><em>size_in</em></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div><div class="memdoc">
<p>Allocate a block of memory with a minimum of 'size' bytes.</p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">size_in</td><td>is the minimum size of the requested block in bytes. </td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>pointer to allocated memory or NULL if no free memory was found.</dd></dl>
<p>Note that the returned value will always be aligned (as defined by MEM_ALIGNMENT). </p>

</div>
</div>
<a id="a7e6b7f11bb50bead9b35515d9a517124"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a7e6b7f11bb50bead9b35515d9a517124">&#9670;&nbsp;</a></span>mem_trim()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void* mem_trim </td>
          <td>(</td>
          <td class="paramtype">void *&#160;</td>
          <td class="paramname"><em>rmem</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">mem_size_t&#160;</td>
          <td class="paramname"><em>new_size</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div><div class="memdoc">
<p>Shrink memory returned by <a class="el" href="mem_8c.html#af418ade27d91d41e6143dba2cc246b0f">mem_malloc()</a>.</p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">rmem</td><td>pointer to memory allocated by mem_malloc the is to be shrinked </td></tr>
    <tr><td class="paramname">new_size</td><td>required size after shrinking (needs to be smaller than or equal to the previous size) </td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>for compatibility reasons: is always == rmem, at the moment or NULL if newsize is &gt; old size, in which case rmem is NOT touched or freed! </dd></dl>

</div>
</div>
<h2 class="groupheader">Variable Documentation</h2>
<a id="a6da602f2bbf1d555556f9260b3b8ad5f"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a6da602f2bbf1d555556f9260b3b8ad5f">&#9670;&nbsp;</a></span>ram_heap</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">u8_t ram_heap[(((((( 1600)+ 1 - 1U) &amp;~(1 -1U))+(2U *(((sizeof(struct mem))+ 1 - 1U) &amp;~(1 -1U))))+ 1 - 1U))]</td>
        </tr>
      </table>
</div><div class="memdoc">
<p>If you want to relocate the heap to external memory, simply define LWIP_RAM_HEAP_POINTER as a void-pointer to that location. If so, make sure the memory at that location is big enough (see below on how that space is calculated). the heap. we need one struct mem at the end and some room for alignment </p>

</div>
</div>
</div><!-- contents -->
</div><!-- doc-content -->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
  <ul>
    <li class="navelem"><a class="el" href="dir_68267d1309a1af8e8297ef4c3efbcdba.html">src</a></li><li class="navelem"><a class="el" href="dir_aebb8dcc11953d78e620bbef0b9e2183.html">core</a></li><li class="navelem"><a class="el" href="mem_8c.html">mem.c</a></li>
    <li class="footer">Generated by
    <a href="http://www.doxygen.org/index.html">
    <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.8.13 </li>
  </ul>
</div>
</body>
</html>
